﻿using AutoMapper;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Travel.API.Dto;
using Travel.API.Models;
using Travel.API.SearchModel;
using Travel.API.Services;

namespace Travel.API.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class TouristRouteController : ControllerBase
    {
        private ITouristRouteServices _touristRouteServices;
        private readonly IMapper _mapper;
        public TouristRouteController(ITouristRouteServices touristRouteServices,IMapper mapper)
        {
            _touristRouteServices = touristRouteServices;
            _mapper = mapper;
        }
        [HttpGet]
        [HttpHead]
        public IActionResult GetTouristRoute([FromQuery] TouristRouteSearch paramaters)
        {
            var data = _touristRouteServices.GetTouristRoutes(paramaters.Keyword,paramaters.RatingOperator,paramaters.RatingValue);      
            if (data == null || data.Count() == 0)
            {
                return NotFound("找不到资源404");
            }
            var datadto = _mapper.Map<IEnumerable<TouristRouteDto>>(data);
            return Ok(datadto);
        }

        [HttpGet("{TouristRouteId}")]
        public IActionResult GetTouristRoute(Guid TouristRouteId)
        {
            var data = _touristRouteServices.GetTouristRoutes(TouristRouteId);
            if (data == null)
            {
                return NotFound($"找不到不到{TouristRouteId}资源");
            }
            var dataDto = _mapper.Map<TouristRouteDto>(data);
            return Ok(dataDto);
        }
    }
}
